import React, { Component } from "react";
import "./css/shoppingCart.css";
import EmptyCart from "./empty-cart"; //空购物车组件
import Carstlist from "../../containers/cartList/cartListContainer"; //购物车列表组件(从action中获取)
import cookie from "react-cookies";
import find from "../../api/cartList/cartApi";
class ShoppingCart extends Component {
  constructor() {
    super();
    this.state = {
      isFull: ""
    };
  }
  render() {
    find(cookie.load("uid")).then(res => {
      this.setState({
        isFull: res.data.data.length
      });
    });
    // console.log(this.state.item);
    let uid = cookie.load("uid");
    let { isFull } = this.state;
    if (uid) {
      if (isFull) {
        return (
          <div id="shoppingCart">
            <p id="Shopping-title">购物车</p>
            <div id="cart-list">
              <Carstlist />
            </div>
          </div>
        );
      } else {
        return (
          <div id="shoppingCart">
            <p id="Shopping-title">购物车</p>
            <div id="cart-list">
              <EmptyCart />
            </div>
          </div>
        );
      }
    } else {
      return (
        <div id="shoppingCart">
          <p id="Shopping-title">购物车</p>
          <div id="cart-list">
            <EmptyCart />
          </div>
        </div>
      );
    }
  }
}

export default ShoppingCart;
